<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2018/8/1
 * Time: 9:26
 */

header("Content-Type:text/html;charset=utf-8");
if ($_SERVER["REQUEST_METHOD"] == "POST"){
    $Uname = $_REQUEST["Uname"];
    $Upwd = $_REQUEST["Upwd"];
//    echo "Uname : ".$Uname;
//    echo "Upwd : ".$Upwd;


    $raw = array('status' => 0, 'msg' => '初始化');
//    用户账号验证
//    数据库链接

    $con = mysqli_connect("127.0.0.1:3306","root","","jiayouhui");

    if (!$con) {
        $raw = array('status' => 0, 'msg' => '数据库链接错误');
        $result = json_encode($raw);
//        echo  $result;
        mysqli_close($con);
        die('Could not connect: ' . mysqli_connect_error());
    }
    mysqli_select_db($con,"jiayouhui");
    $sql = "SELECT * FROM user_account where Uname = '".$Uname."' ";

//    echo  $sql;

//    $sql_result的值为true或false

    $sql_result = mysqli_query($con, $sql);

//    如果没有数据，mysqli_fetch_array返回false

    if (mysqli_fetch_array($sql_result, MYSQLI_ASSOC)){
        $raw = array('status' => 0, 'msg' => '注册失败,该用户已经注册');
    }else{
        $sql1 = "INSERT INTO user_account(Uname,Upwd) VALUES ('".$Uname."','".$Upwd."')";
        $sql_result1 = mysqli_query($con, $sql1);
        if($sql_result1){
            $raw = array('status' => 1, 'msg' => '注册成功');
        }else{
            $raw = array('status' => 0, 'msg' => '注册失败,出现未知错误！');
        }
    }
    $result = json_encode($raw);
    echo  $result;
    mysqli_close($con);
}else{
    echo "fuck you";
}
